<template>
  <view class="container">
    <z-paging
      ref="paging"
      v-model="itemList"
      @query="queryList"
      :fixed="true"
      :auto="false"
      :auto-show-back-to-top="true"
      :empty-view-img="`${getImageUrl('empty.png')} `"
      empty-view-text="暂无数据~"
      :empty-view-img-style="imgStyle"
    >
      <view slot="top">
        <u-navbar
          backIconColor="#333333"
          title-size="36"
          :title="title"
          height="50"
          :is-back="true"
          :border-bottom="false"
          title-color="#333333"
        >
        </u-navbar>
        <view
          v-if="extra"
          class="dis-flex flex-x-center flex-y-center"
          style="margin: 15rpx 20rpx 0 20rpx"
        >
          <text>{{ subTitle }}</text>
          <text style="color: orange">¥{{ extra.numberSum }}</text>
        </view>
      </view>
      <view class="list-box" v-for="(item, index) in itemList" :key="index">
        <view class="top dis-flex flex-y-between">
          <view class="cate">{{ item.note }}</view>
          <view class="num sub" v-if="item.bonusMoney < 0"
            >{{ (item.bonusMoney * 0.01).toFixed(2) }}
          </view>
          <view class="num add" v-else>+{{ (item.bonusMoney * 0.01).toFixed(2) }}</view>
        </view>
        <view class="bottom dis-flex flex-y-between">
          <view class="date">{{ $u.timeFormat(item.createTime, 'yyyy-mm-dd hh:MM') }}</view>
          <view class="y" v-if="item.status == 0">待结算</view>
          <view class="y" v-else-if="item.status == 1">已结算</view>
          <view class="y" v-else-if="item.status == 2 || item.status == 3">已失效</view>
        </view>
      </view>
    </z-paging>
    <u-picker v-model="showPiker" :params="params" @confirm="comfirmDate"></u-picker>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      itemList: [],
      year: '',
      month: '',
      day: '',
      showPiker: false,
      params: {
        year: true,
        month: true,
        day: false
      },
      extra: null,
      title: '',
      subTitle: '',
      status: 0
    }
  },
  onLoad(options) {
    this.status = options.status || 0
    if (this.status == 0) {
      this.title = '待入账收益'
      this.subTitle = '累计待入账收益：'
    } else {
      this.title = '今日收益'
      this.subTitle = '今日累计收益：'
      let today = new Date()
      this.year = today.getFullYear()
      this.month = today.getMonth() + 1 < 10 ? '0' + (today.getMonth() + 1) : today.getMonth() + 1
      this.day = today.getDate() < 10 ? '0' + today.getDate() : today.getDate()
    }
    this.queryList(1)
  },
  methods: {
    routeTo(url) {
      this.$utils.route(url)
    },
    queryList(pageNo = 1, pageSize = 10) {
      if (pageNo === 1) {
        this.itemList = []
      }
      this.$u
        .get('/app-api/brokerage/merchant/record/page', {
          pageNo,
          pageSize,
          year: this.year,
          month: this.month,
          day: this.day,
          status: this.status
        })
        .then((res) => {
          this.$refs.paging.complete(res.data.list)
          this.extra = res.data.extra
        })
    },
    comfirmDate(res) {
      this.year = res.year
      this.month = res.month
      this.queryList(1)
    }
  }
}
</script>

<style scoped lang="scss">
.rule_box {
  padding: 45rpx 30rpx 35rpx 30rpx;

  .tl {
    font-weight: 600;
    font-size: 34rpx;
    margin-bottom: 45rpx;
    text-align: center;
  }

  .content {
    font-size: 30rpx;
    line-height: 45rpx;
  }

  .bt {
    width: 240rpx;
    height: 72rpx;
    background: #10a28f;
    border-radius: 36rpx;
    margin: auto;
    font-size: 30rpx;
    color: #ffffff;
    line-height: 72rpx;
    margin-top: 35rpx;
    text-align: center;
  }
}

.cell {
  margin-bottom: 20rpx;

  .label {
    font-size: 24rpx;
    color: #333333;
    margin-right: 20rpx;
  }

  .value {
    font-weight: 600;
    font-size: 48rpx;
    color: #333333;
  }

  .cell-right {
    font-size: 24rpx;
    color: #999999;
  }

  .cell-right-1 {
    font-size: 36rpx;
  }

  .cell-right-2 {
    font-size: 24rpx;
    width: 220rpx;
    height: 56rpx;
    line-height: 56rpx;
    background: #10a28f;
    border-radius: 28rpx;
    color: #ffffff;
    align-items: center;

    .r-a {
      margin-left: 10rpx;
    }

    .r-b {
      width: 120rpx;
      height: 50rpx;
      background: #d7f5f1;
      border-radius: 25rpx;
      text-align: center;
      font-size: 30rpx;
      color: #ff6f10;
      margin-right: 3rpx;
    }
  }
}

.cell:last-child {
  margin-bottom: 0;
}

.list-box {
  background: #ffffff;
  border-radius: 10rpx;
  margin: 15rpx 20rpx;
  padding: 30rpx 20rpx;

  .top {
    font-size: 28rpx;
    margin-bottom: 20rpx;

    .num {
      font-weight: 600;
      font-size: 30rpx;
      color: #333333;
      margin-left: 120rpx;
    }

    .add {
      color: orange;
    }

    .sub {
      color: green;
    }
  }

  .bottom {
    font-size: 24rpx;
    color: #999999;

    .y {
      color: #909399;
    }
  }
}

.list-box:last-child {
  border: none;
}

.headView {
  position: sticky;
  background: #fff;
  z-index: 100;
  height: 85rpx;
  top: 0px;
  padding-top: 25rpx;

  .top {
    font-size: 30rpx;
    margin-bottom: 20rpx;
  }

  .bottom {
    font-size: 26rpx;
    color: #999999;
  }
}
</style>
